function filterBy<T>(array:T[], predicate:(value:T) => boolean) {
    let result:T[] = []
    array.forEach(item => {
        if (predicate(item)) {
            result.push(item)
        }
    })
    return result
}

let newArray = filterBy<number>([1, 2, 3, 4, 5, 6], item => item > 3)
console.log(newArray);

let newCity =filterBy<string>(["合肥", "马鞍山", "攀枝花", "石家庄", "南京"], item => item.length > 2)
console.log(newCity)

interface MyUser {
    name: string
    age: number
}

filterBy<MyUser>([{name: "小花", age: 18}, {name: "黎明", age: 23}, {name: "张三", age: 43}], item => item.age > 20)